Linux Quickstart π§π
Published at Nov 27, 2024
π Introduction
Welcome to this quick start guide for Linux! The goal isnβt to memorize every command, but to understand the workflow and learn how to learn. Stick around for a bonus tip at the end! π
Basic Commands
ls
- List Directory Contents ποΈ
When you first open a terminal, it might feel like a dark and empty abyss. Letβs turn
on the lights with ls
π‘.
- What it does: Lists information about files and directories. By default, it sorts entries alphabetically.
- Finding out more: Use
man ls
to see the manual page.
Common Parameters (Flags)
Parameters modify how a command works. They usually have a short (-a
) and
long (--all
) form.
-a
or--all
: Show all entries, including hidden files (those starting with.
).-l
: Use a long listing format. This shows permissions, owner, group, size, modification date, and filename.-r
or--reverse
: Reverse the order of the sort.-t
: Sort by modification time, newest first. Combine with-l
to see the times (ls -lt
).
Example Usage:
ls # Basic listing
ls -a # List all files (including hidden)
ls -l # Long listing format
ls -al # Long listing of all files
ls -alr # Long listing, all files, reversed order
ls -lt # Long listing, sorted by time (newest first)
Quick Tip: Use
Ctrl+L
to clear the terminal screen.
man
- The System Manual π
man
is your key π to understanding commands.
- What it does: Displays the systemβs reference manuals (manual pages) for commands, utilities, or functions. It uses a pager program like
less
to display the content. - Usage:
man <command_name>
(e.g.,man ls
,man man
).
Navigating man
Pages (using less
)
Press h
inside man
for a help screen.
- Moving:
β
/β
orEnter
: Move down/up one line.Spacebar
/PageDown
: Move down one page.PageUp
: Move up one page.
- Jumping:
gg
: Go to the beginning of the page.G
(Shift+g): Go to the end of the page.
- Searching:
/search_term
: Search forward forsearch_term
.?search_term
: Search backward forsearch_term
.n
: Go to the next search result (in the direction you searched).N
(Shift+n): Go to the previous search result.
- Quitting:
q
: Quit theman
page viewer.
Example: Letβs find the time sorting option in ls
.
- Open the manual:
man ls
- Search forward for βtimeβ:
/time
- Press
n
to cycle through results until you find the-t
flag.
Navigating the File System πΊοΈ
Understanding the Hierarchy π
The Linux file system is a hierarchy, like an inverted tree π³ or a staircase, starting from the root directory (/
).
- Root Directory:
/
- The top level. - Home Directory:
/home/<username>
(e.g.,/home/crispy
) - Your personal space. - Path Separator:
/
- Used to separate directories in a path.
You can visualize the structure using the
tree
command
cd
- Change Directory
- What it does: Changes your current working directory.
Paths
- Absolute Path: Specifies the location from the root directory (
/
). Always starts with/
.- Example:
cd /home/crispy/Documents
- Example:
- Relative Path: Specifies the location relative to your current directory. Does not start with
/
..
(dot): Represents the current directory...
(dot-dot): Represents the parent directory (one level up).- Example: If you are in
/home/crispy
:cd Documents
(orcd ./Documents
) moves into theDocuments
subdirectory.cd ..
moves up to/home
.
Example Workflow:
pwd # Check current directory (e.g., /home/crispy)
cd /home/crispy # Go to home using absolute path
pwd # Confirm: /home/crispy
cd Documents # Go down into Documents (relative path)
pwd # Confirm: /home/crispy/Documents
cd .. # Go up one level (relative path)
pwd # Confirm: /home/crispy
pwd
- Print Working Directory
- What it does: Shows the full path of your current directory.
Viewing Files π
cat
- Concatenate and Display Files π
- What it does: Reads files sequentially and writes their content to standard output (your terminal).
- Concatenation: If you provide multiple filenames,
cat
displays them one after the other.
Example Usage:
# Display a single file
cat reminder.txt
# Display multiple files, one after the other
cat file1.txt file2.txt file3.txt
Bonus: Quick References with curl
and cheat.sh
π
Sometimes you just need a quick reminder or example. cheat.sh
is a community-driven cheat sheet service accessible via curl
π.
curl
- Transfer Data from URLs
- What it does: A versatile tool to transfer data using various protocols, including HTTP/HTTPS for web pages.
- Basic Usage:
curl <url>
cheat.sh
- Command Cheat Sheets
- Access:
curl cheat.sh
- Get help for a specific command:
curl cheat.sh/<command_name>
- Short alias: Often,
cht.sh
works too:curl cht.sh/<command_name>
Example Usage:
curl cheat.sh # General help/intro
curl cheat.sh/ls # Cheat sheet for ls
curl cht.sh/grep # Cheat sheet for grep
curl cheat.sh/tar # Cheat sheet for tar
cheat.sh
provides common use cases, explanations, and often a TL;DR section for very quick examples. Explore the :help
and :intro
sections (curl cheat.sh/:help
).
Conclusion π―
Weβve covered the basics:
ls
: Listing files ποΈman
: Reading manuals πcd
,pwd
: Navigating directories π²cat
: Viewing files πcurl
,cheat.sh
: Getting quick help π
The key is not memorizing absolutely everything π§ but knowing how to find information (
man
,cheat.sh
) and understanding how Linux works from a high level πΈ
Keep exploring, stay curious, and practice! π